package com.hbwxz.admin.controller;


import com.hbwxz.admin.pojo.CommodityParam;
import com.hbwxz.admin.pojo.CommoditySku;
import com.hbwxz.admin.pojo.CommoditySpuDetail;
import com.hbwxz.admin.service.CommodityService;
import com.hbwxz.common.response.CommonResponse;
import com.hbwxz.common.response.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/commodity")
public class CommodityController {

    @Autowired
    private CommodityService commodityService;

    //保存商品信息
    @RequestMapping("/create")
    public CommonResponse createCommodity(@RequestBody CommodityParam commodityParam) {
        commodityService.createCommodity(commodityParam);
        return ResponseUtils.okResponse(null);
    }

    @RequestMapping("/spu/detail/{id}")
    public CommonResponse getSpuDetail(@PathVariable Long id){
        CommoditySpuDetail spuDetail = commodityService.getSpuDetail(id);
        return ResponseUtils.okResponse(spuDetail);
    }

    @RequestMapping("/sku/list/{id}")
    public CommonResponse getSkuBySpuId(@PathVariable Long spuId){
        List<CommoditySku> skus = commodityService.getSkuBySpuId(spuId);
        return ResponseUtils.okResponse(skus);
    }

    @RequestMapping("/update")
    public CommonResponse updateCommodity(@RequestBody CommodityParam commodityParam) {
        commodityService.updateCommodity(commodityParam);
        return ResponseUtils.okResponse(null);
    }

    @Deprecated
    @RequestMapping(value = "/on-sale/spu/{spuId}",method = RequestMethod.POST)
    public CommonResponse onSale(@PathVariable Long spuId) {
        commodityService.onSale(spuId);
        return ResponseUtils.okResponse(null);
    }

    @Deprecated
    @RequestMapping(value = "/on-sale1/spu/{spuId}",method = RequestMethod.POST)
    public CommonResponse onSale1(@PathVariable Long spuId) {
        commodityService.onSale1(spuId);
        return ResponseUtils.okResponse(null);
    }

    @Deprecated
    @RequestMapping(value = "/on-sale2/spu/{spuId}",method = RequestMethod.POST)
    public CommonResponse onSale2(@PathVariable Long spuId) {
        commodityService.onSale2(spuId);
        return ResponseUtils.okResponse(null);
    }

    @Deprecated
    @RequestMapping(value = "/on-sale3/spu/{spuId}",method = RequestMethod.POST)
    public CommonResponse onSale3(@PathVariable Long spuId) {
        return ResponseUtils.okResponse(commodityService.onSale3(spuId));
    }

    @RequestMapping(value = "/on-sale4/spu/{spuId}",method = RequestMethod.POST)
    public CommonResponse onSale4(@PathVariable Long spuId) {
        return commodityService.onSale4(spuId);
    }


}
